package com.gxa.controller;

import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.param.MyTableParam;
import com.gxa.pojo.Empl;
import com.gxa.pojo.Goods;
import com.gxa.service.GoodsService;
import com.gxa.service.orderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("goods")
public class goodsController {

    @Autowired
    private GoodsService service;

    @GetMapping("/list/page")
    public String listPage(Integer id , HttpSession session){
        session.setAttribute("customerId",id);
        return "/goods/goods_list";
    }

    @PostMapping("/list/Pagedata")
    @ResponseBody
    public LayR list1(MyTableParam param){
        return service.list(param);
    }

    @GetMapping("/edit/page")
    public String editPage(Integer id, Model model){
        model.addAttribute("goodsId", id);
        return "/goods/goods_edit";
    }

    @PostMapping("/detail")
    @ResponseBody
    public R detail(Integer id){
        return service.findById(id);
    }

    @PostMapping("/edit/do")
    @ResponseBody
    public R edit(Goods goods){
        return service.edit(goods);
    }

    @PostMapping("/buy")
    @ResponseBody
    public R buy(@RequestParam("ids[]") String[] ids,HttpSession session){
        return service.buy(ids,session);
    }

}
